package com.come4loves.game.module.fight.action;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import com.come4loves.game.module.battle.helper.PBConvertHelper;
import com.come4loves.game.module.fight.constants.FighterAttribute;
import com.come4loves.game.module.fight.model.FightCard;
import com.come4loves.game.proto.BattleProto;
import com.google.protobuf.GeneratedMessage.Builder;

public class AttributeChangeAction extends Action {
	private Map<FighterAttribute, Integer> attChangeValue = new HashMap<FighterAttribute, Integer>();
	private Map<FighterAttribute, Boolean> attChangeFlag = new HashMap<FighterAttribute, Boolean>();
	public AttributeChangeAction(FightCard fightCard) {
		super(fightCard.getId());
	}
	
	public void addAttributeChange(FighterAttribute key, int value, boolean flag){
		attChangeValue.put(key, value);
		attChangeFlag.put(key, flag);
	}


	@Override
	public Builder<?> toProtocolBufferBuilder() {
		BattleProto.AttributeChangeAction.Builder builder = BattleProto.AttributeChangeAction.newBuilder();
		BattleProto.AttributeChangeData.Builder attDataBuilder = BattleProto.AttributeChangeData.newBuilder();
		attDataBuilder.setId((int) this.getId());
		for (Entry<FighterAttribute, Integer> entry : attChangeValue.entrySet()) {
			BattleProto.AttributeEntry.Builder b = BattleProto.AttributeEntry.newBuilder();
			b.setKey(PBConvertHelper.convertAttribute(entry.getKey()));
			b.setValue(entry.getValue());
			b.setFlag(attChangeFlag.get(entry.getKey()));
			attDataBuilder.addAttributeChange(b);
		}
		builder.setData(attDataBuilder);
		return builder;
	}

}
